package com.rtx.wms.customer.k3.upload.so;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rtx.edi.platform.field.service.PlFieldMappingService;
import com.rtx.wms.customer.k3.upload.K3UploadService;
import com.rtx.wms.std.common.bean.WmsConstant;
import com.rtx.wms.std.so.bean.ApiOrdersfinish;

@Component
public class K3OrderService extends K3UploadService{
	
	Logger log = LoggerFactory.getLogger(this.getClass());

	@Autowired
	PlFieldMappingService plFieldMappingService;

	@Override
	protected String resolveCallBackAPICode(Object data) {
		ApiOrdersfinish finish = (ApiOrdersfinish) data;
		return finish.getRtxbsart();
	}


	@Override
	protected void resolveResonse(String response,Object data) {
		ApiOrdersfinish finish = (ApiOrdersfinish) data;
		try {
			JSONObject res = JSON.parseObject(response,JSONObject.class);
			String code = res.getString("code");
			if(!"0".equals(code)) {
				finish.setEdiflag(WmsConstant.FAIL_FLAG);
				finish.setEdimsg(res.getString("message"));
			}else {
				finish.setEdiflag(WmsConstant.SUCCESS_FLAG);
				finish.setEdimsg(res.getString("message"));
			}
		} catch (Exception e) {
			log.error("",e);
			finish.setEdiflag(WmsConstant.FAIL_FLAG);
			finish.setEdimsg(e.getMessage());
		}
	}
}
